package xmls

var UrlsMapper = []byte(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://raw.githubusercontent.com/zhuxiujia/GoMybatis/master/mybatis-3-mapper.dtd">
<mapper>
    <resultMap id="BaseResultMap" tables="t_urls">
        <id column="id" langType="int"/>
        <result column="detail" langType="string"/>
        <result column="url" langType="string"/>
        <result column="parent_id" langType="string"/>
        <result column="icon" langType="string"/>
        <result column="create_by" langType="string"/>
        <result column="create_time" langType="time.Time"/>
        <result column="update_by" langType="string"/>
        <result column="update_time" langType="time.Time"/>
        <result column="is_delete" langType="bool"
                logic_enable="true"
                logic_undelete="0"
                logic_deleted="1"/>
    </resultMap>

    <deleteTemplate wheres="id?id = #{id}"/>

    <select id="FindUrlsById">
        select *
        from t_urls
        WHERE id in
        <foreach collection='urls' item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and parent_id =0 and is_delete =0
    </select>

    <select id="FindAllUrls">
        select *
        from t_urls
        where is_delete =0
    </select>

    <select id="FindUrlsByParentId">
        select *
        from t_urls
        where
        parent_id = #{id} and is_delete =0
    </select>

	<select id="FindUrlsByCurrentId">
        select *
        from t_urls
        where id in
        <foreach collection='urls' item="item" open="(" close=")" separator=",">
            #{item}
        </foreach> and
        parent_id = #{id} and is_delete =0
    </select>

    <insert id="AddUrl">
        insert into t_urls (detail,parent_id,url,icon,create_by,update_by) values
        (#{detail},#{parent_id},#{url},#{icon},'root','root')
    </insert>

    <selectTemplate wheres="id?id = #{id}"/>

    <select id="GetAllUrls">
        select * from t_urls where 1=1
        <if test="detail != ''">
            and detail like #{'%'+detail+'%'}
        </if>
		<if test="url != ''">
            and url like #{'%'+url+'%'}
        </if>
        and is_delete = 0 and parent_id = 0
        limit #{current} , #{pageSize}
    </select>

    <select id="GetUrlsByUser">
        select * from t_urls
        where id in
        <foreach collection='urls' item="item" open="(" close=")" separator=",">
            #{item}
        </foreach> is_delete = 0
    </select>

    <select id="UpdateUrlById">
        update t_urls set
        detail=#{detail},parent_id=#{parent_id},url=#{url},icon=#{icon},update_by=#{update_by},update_time=#{update_time}
        where id = #{id}
    </select>

    <select id="GetAllUrlsCountByPage">
        select count(1) from t_urls where 1=1
        <if test="detail != ''">
            and detail like #{'%'+detail+'%'}
        </if>
		<if test="url != ''">
            and url like #{'%'+url+'%'}
        </if>
        and is_delete = 0 and parent_id = 0
    </select>
	<update id='UpdateUrlByUserId'>
		update t_user set urls = #{urls} where id = #{id}
	</update>
	<select id='GetUrlsByUserId'>
		select urls from t_user where id =#{id}
	</select>
</mapper>`)
